package com.kx.yooli.kx.wechat.mapper.nplm;

import com.kx.yooli.kx.wechat.entity.nplm.LoanContractEntity;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryCondition;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ILoanContractMapper extends BaseMapper<LoanContractEntity> {
    default  LoanContractEntity selectLoanInfoByNo(String loanNo){
        QueryColumn queryColumn = new QueryColumn("nplm","NPLM_LOAN_CONTRACT",
                "LOAN_NO");
        return  selectOneByCondition(QueryCondition.create(queryColumn,"=",loanNo));
    }

    @UseDataSource("dh")
    @Select("select count(loan_no) from NPLM_LOAN_CONTRACT where loan_no=#{loanNo,jdbcType=VARCHAR} and CONTRACT_STATUS in ('1','2','3')")
    Integer selectCountByLoanNo(String loanNo);
    @UseDataSource("dh")
    @Select("select count(ID) as numCount,sum(loan_amount) as sumAmount ,loan_no as loanNo from NPLM_LOAN_CONTRACT where loan_no=#{loanNo,jdbcType=VARCHAR} and CONTRACT_STATUS in ('1','2','3') group by loan_no")
    List<Map<String, Object>> selectLoanInfoByLoanNo(String loanNo);

    default List<LoanContractEntity> selectListLoanInfoByLoanNo(String loanNo){
        QueryColumn queryColumn = new QueryColumn("nplm","NPLM_LOAN_CONTRACT",
                "LOAN_NO");
      return   selectListByCondition(QueryCondition.create(queryColumn,"=",loanNo).and(" phase_number !=0"));
    }
}
